package com.example.search.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.search.databinding.ItemKeywordLayoutBinding


class KeyWordListAdapter constructor(private val list:MutableList<String>):RecyclerView.Adapter<
        KeyWordListAdapter.keywordItemViewHolder>() {

    inner class keywordItemViewHolder constructor(val databinding:ItemKeywordLayoutBinding):RecyclerView
    .ViewHolder(databinding.root)

    private var itemClickListener:OnItemClickListener?=null
    fun setonItemClickener(listener:OnItemClickListener){
        itemClickListener = listener
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): keywordItemViewHolder {
        return keywordItemViewHolder(ItemKeywordLayoutBinding.inflate(LayoutInflater.from(parent.context),parent,false))
    }

    override fun getItemCount(): Int = list.size

    override fun onBindViewHolder(holder: keywordItemViewHolder, position: Int) {
        holder.databinding.tvKeyword.text = list[position]
        holder.databinding.tvKeyword.setOnClickListener{
            itemClickListener?.onItemChildclick(it,position)
        }

    }
    interface OnItemClickListener{
        fun onItemChildclick(v:View?,position:Int)
    }


}